package ru.teleology.cubefs.api.reflection.value;

import java.math.BigInteger;

public final class IDValue {
	private String value = "0x0";
	public IDValue() {}
	
	public IDValue(String text) {
		value = text != null ? text : "0x0";
	}
	
	public String toString() {
		return value;
	}
	
	public String str() {
		return value;
	}
	
	public boolean IsNull() 
	{
		if (value.startsWith("0x")) 
		{
			if (value.length() > 2) 
			{
				BigInteger ivalue = new BigInteger(value.substring(2), 16);
				return ivalue.equals(BigInteger.ZERO);
			}
			else {
				throw new NumberFormatException("Invalid ID value format: "+value);
			}
		}
		else {
			throw new NumberFormatException("Invalid ID value prefix: "+value); 
		}

	}
	
	public void clear() {
		value = "0x0";
	}
	
	public boolean equals(Object other) {
		if (other instanceof IDValue) 
		{
			IDValue other_value = (IDValue) other;
			return value.equals(other_value.value);
		}
		else {
			return false;
		}
	}
}
